package com.serenegiant.usbcameratest0;

import java.lang.reflect.Field;

public class ReflectUtils {

    public static <F> F getReflectField(Class clazz,
                                        Object obj,
                                        String fieldName,
                                        Class<F> fieldClass) throws Exception {
        boolean staticField = false;
        if (obj == null) {
            staticField = true;
        } else {
            clazz = obj.getClass();
        }
        Field f = clazz.getDeclaredField(fieldName);
        f.setAccessible(true);
        if (staticField) return fieldClass.cast(f.get(null));
        else return fieldClass.cast(f.get(obj));
    }
}
